package com.asa.shishu;

import com.asa.HanShu;
import com.asa.utils.Calculate;
import com.asa.utils.MathUtils;
/**
 * 	泰勒展开
 * 	它可以将函数转化成唯一的幂函数的线性组合
 * 	幂函数正交化可以得到各种正交多项式
 * 	这又包含了，一个函数可以得到其唯一的，各种正交的线性组合
 * @author Administrator
 *
 */
public class TaylorFormula {
	
	
	/**
	 * 	没有测试
	 * @param hanShu
	 * @param n
	 * @param x0
	 * @return	泰勒展开的每一项的实数值
	 */
	public static double[] base(final HanShu hanShu,int n,double x0) {
		
		double[] a = new double[n];
		
		HanShu hashudao = new HanShu() {
			
			@Override
			public double hanshu(double t, double x) {
				// TODO Auto-generated method stub
				return 0;
			}
			
			@Override
			public double hanshu(double x) {
				// TODO Auto-generated method stub
				return hanShu.hanshu(x);
			}
		};
		for (int i = 0; i < a.length; i++) {
			double fn = 0;
			
			if (i!=0) {
				final HanShu hashudaopre = hashudao;
					
				hashudao = new HanShu() {
					
					@Override
					public double hanshu(double t, double x) {
						// TODO Auto-generated method stub
						return 0;
					}
					
					@Override
					public double hanshu(double x) {
						// TODO Auto-generated method stub
						return MathUtils.dao(x, hashudaopre);
					}
				};
			}
			
			
			fn = hashudao.hanshu(x0);

			int jiecheng = Calculate.jiecheng(i);
			
			a[i] = fn/jiecheng;
		}
		
		
		
		
		
		return a;
		
	}
	
	
	public static void main(String[] args) {
		System.out.println(Calculate.jiecheng(3));
	}
	
	

}
